﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Sample.Database.Structure.Entity;
using Sample.Database.Structure.Interface;

namespace Sample.Test.Database.Mock
{
    public class EntityOneRepositoryMock : IRepository<EntityOne>
    {
        private List<EntityOne> entities = new List<EntityOne>();

        public void Dispose()
        {

        }

        public IQueryable<EntityOne> All { get { return entities.AsQueryable(); } }
        public void SaveChanges()
        {

        }

        public void Add(EntityOne content)
        {
            entities.Add(content);
        }

        public void Delete(EntityOne content)
        {
            entities.Remove(content);
        }

        public void Delete(Expression<Func<EntityOne, bool>> predicate)
        {
            entities.Where(predicate.Compile()).ToList().ForEach(x => entities.Remove(x));
        }

        public IQueryable<EntityOne> Find(Expression<Func<EntityOne, bool>> predicate)
        {
            return entities.Where(predicate.Compile()).AsQueryable();
        }

        public EntityOne Single(Expression<Func<EntityOne, bool>> predicate)
        {
            return entities.First(predicate.Compile());
        }

        public EntityOne First(Expression<Func<EntityOne, bool>> predicate)
        {
            return entities.First(predicate.Compile());
        }

        public int Count()
        {
            return entities.Count;
        }

        public int Count(Expression<Func<EntityOne, bool>> criteria)
        {
            return entities.Where(criteria.Compile()).Count();
        }
    }
}
